<?php

Class ReportAction extends BaseAction {
	/*
	  +----------------------------------------------------------
	 * 删帖请求处理
	  +----------------------------------------------------------
	 */

	public function Index() {
		import("Web.ORG.Util.Page");
		//搜索栏
		$Report = D('Report');
		switch ($_GET['filter']) {
			case "processed":
				$where["status"] = array("gt", 0);
				break;
			default :
				$where["status"] = array("eq", 0);
				break;
		}
		$count = $Report->where($where)->count();
		$Page = new Page($count);
		$show = $Page->show();
		$report = $Report->relation('user')->where($where)->order("report_id desc")->limit($Page->firstRow . ',' . $Page->listRows)->select();
		$this->assign('list', $report);
		$this->assign('pages', $show);
		$this->display();
	}

	public function dispose() {
		$report_id = $_REQUEST['id'];
		$act = $_REQUEST['act'];
		$content = $_REQUEST['content'];
		empty($act) && $this->ajaxReturn(null, '请选择操作类型!', -3);
		empty($report_id) && $this->ajaxReturn(null, '参数错误!', -2);

		//遍历操作所选记录
		$Report = D('Report');
		$report = $Report->find($report_id);
		//根据操作类型做出处理
		switch ($act) {
			//同意请求并隐藏帖子
			case 'delete':
				//根据report_type类型分别进行隐藏  1:tweets 2:comment
				if ((int) $report['report_type'] == 1) {
					$result = D('Tweets')->where('tweets_id =' . $report['object_id'])->setField('status', 0);
					//发送提醒给用户
					$tweets = M('Tweets')->find($report['object_id']);
					if ($tweets) {
						notice_log($tweets["user_id"], 4, $tweets["school_id"], $tweets['tweets_id']);
						notice_log($report["user_id"], 8, $tweets["school_id"], $tweets['tweets_id'], array(
							"content" => $content,
						));
					}
				} else if ((int) $report['report_type'] == 2) {
					$result = D('Comment')->where('comment_id =' . $report['object_id'])->setField('status', 0);
					//发送提醒给用户
					$comment = M('Comment')->find($report['object_id']);
					if ($comment) {
						notice_log($comment["user_id"], 7, $comment["school_id"], $comment['tweets_id'], array(
							"comment_id" => $report['object_id'],
						));
						notice_log($report["user_id"], 9, $comment["school_id"], $comment["tweets_id"], array(
							"content" => $content,
							"comment_id" => $report['object_id'],
						));
					}
				}else
					$this->ajaxReturn(null, '不存在该记录!', -1);
				//设置report记录状态为已处理																			
				$Report->where('report_id =' . $report_id)->setField(array('status', 'dispose_time'), array(1, time()));
				$this->ajaxReturn(null, '操作成功!', 1);
				break;
			//拒绝请求返回原因
			case 'refuse':
				//根据report_type类型分别进行状态恢复  1:tweets 2:comment
				if ((int) $report['report_type'] == 1) {
					//发送提醒给用户
					$tweets = M("Tweets")->find($report['object_id']);
					if($tweets){
						notice_log($report["user_id"], 10, $tweets["school_id"], $report['object_id'], array(
							"content" => $content,
						));
					}
				} else if ((int) $report['report_type'] == 2) {
					$comment = M("Comment")->find($report['object_id']);
					if ($comment) {
						//发送提醒给用户
						notice_log($report["user_id"], 11, $comment["school_id"], $comment["tweets_id"], array(
							"content" => $content,
							"comment_id" => $report['object_id'],
						));
					}
				}else
					$this->ajaxReturn(null, '不存在该记录!', -1);
				//设置report记录状态为已处理
				$Report->where('report_id =' . $report_id)->setField(array('status', 'dispose_time'), array(2, time()));
				$this->ajaxReturn(null, '操作成功!', 1);
				break;
		}
	}

}

?>
